home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / EVENTS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-23  |  11.4 KB  |  398 lines

  1. /********************************************
  2.     file: events.c
  3.     utility:
  4.     date: 1989
  5.     author: Jim Charlton
  6.     modifications:
  7.         1996: C. Moreau: 
  8.     comments: 
  9. *********************************************/
  10.  
  11. /********************************************
  12.     includes
  13. *********************************************/
  14. #ifdef __PUREC__ 
  15. #include <aes.h>
  16. #include <compend.h>
  17. #else
  18. #include <aesbind.h>
  19. #endif
  20.  
  21. #include "button.h"    
  22. #include "cursor.h"
  23. #include "events.h"
  24. #include "keys.h"
  25. #include "main.h"
  26. #include "menu.h"
  27. #include "onepage.h"    
  28. #include "slider.h"
  29. #include "wind.h"
  30.  
  31. /********************************************
  32.     defines
  33. *********************************************/
  34.  
  35. /********************************************
  36.     locals vars declarations & definitions
  37. *********************************************/
  38. static int edit, pos_edit;
  39.  
  40. /********************************************
  41.     globals vars declarations
  42. *********************************************/
  43. int message[8];            /* AES message array */
  44. int objet;
  45.  
  46. /********************************************
  47.     locals functions declarations
  48. *********************************************/
  49. static int xform_do (int *,int *,int *,int *,int *,int *,int *,int *);
  50. static int parent (OBJECT *adr, int object);
  51. static int prev (OBJECT *adr);
  52. static int next (OBJECT *adr);
  53.  
  54. /********************************************
  55.     globals functions definitions
  56. *********************************************/
  57. /*
  58.     name: TaskMaster
  59.     utility: Handle Application Events.
  60.     comment: 
  61.     parameters:
  62.     return:
  63.     date: 1989
  64.     author: Jim Charlton
  65.     modifications:
  66.         1995: C. Moreau: 
  67. */
  68. void TaskMaster(void)
  69. {
  70.     int event;            /* The event code.                    */
  71.     int    mousex, mousey;    /* The current mouse position.        */
  72.     int mousebutton;    /* The state of the mouse button    */
  73.     int keymods;        /*  The state of the keyboard modifiers.
  74.                             (shift, ctrl, etc). */
  75.     int clicks;            /*    The number of mouse clicks that occurred in the 
  76.                             given time. */
  77.     int button = TRUE;    /* desired Button state                */
  78.  
  79.     for (;;) 
  80.     {
  81.         putcur();    /* cursor on    */
  82.  
  83.         event = xform_do(
  84.              &button,        /* desired key state                        */
  85.             message,        /* The message buffer                         */
  86.             &mousex,        /* The x-coordinate of the mouse at event.  */
  87.             &mousey,        /* The y-coordinate of the mouse at event.  */
  88.             &mousebutton,    /* The state of the mouse buttons at event. */
  89.             &keymods,        /* The state of the keyboard modifiers.     */
  90.             &keycode,        /* The key code for the key pressed.        */
  91.             &clicks            /* The number of times the event occurred    */
  92.         );
  93.         
  94.         putcur();    /* cursor off    */
  95.  
  96.         if (event & MU_MESAG) 
  97.         {
  98.             switch (message[0]) 
  99.             {
  100.                 /*
  101.                     Window Support
  102.                 */
  103.                 case WM_REDRAW:
  104.                 case WM_TOPPED:
  105.                 case WM_FULLED:
  106.                 case WM_ARROWED:
  107.                 case WM_HSLID:
  108.                 case WM_VSLID:
  109.                 case WM_SIZED:
  110.                 case WM_MOVED:
  111.                 case WM_NEWTOP:
  112.                 case WM_CLOSED:
  113.                 case WM_BOTTOM:
  114.                 case WM_ICONIFY:
  115.                 case WM_UNICONIFY:
  116.                     window_do(message);
  117.                     break;
  118.  
  119.                 /*
  120.                     Menu Support
  121.                 */
  122.                 case MN_SELECTED:
  123.                     do_menu(message[3], message[4]);
  124.                     button ^= TRUE;    
  125.                     break;
  126.  
  127.                 /*
  128.                     Desk Accessory Support
  129.                 */
  130.                 case AC_OPEN:
  131.                 case AC_CLOSE:        break;
  132.  
  133.                 /*
  134.                     System Shut down Support
  135.                 */
  136.                 case AP_TERM:
  137.                     shutdown(0);
  138.             }
  139.         }
  140.         else if (event & MU_KEYBD)
  141.         {
  142.             do_kbd(keycode, keymods);
  143.         }    
  144.         else if (event & MU_BUTTON)
  145.         {
  146.             if(button && thefrontwin)
  147.                 do_button(mousex, mousey);
  148.             button ^= TRUE;
  149.         }
  150.     }
  151. }
  152.  
  153. /********************************************
  154.     locals functions definitions
  155. *********************************************/
  156. /*
  157.     name: xform_do
  158.     utility: Replace form_do of GEM
  159.     comment: 
  160.     parameters:
  161.     return:
  162.     date: january 1994
  163.     author: C. Attard
  164.     modifications:
  165.         1995: C.Moreau: Addapted to XXed
  166.         11 may 96: C.Moreau: Changed order of cursor init when clic on editable
  167. */
  168. static int xform_do (int *button, int *message,
  169.          int *mousex, int *mousey, int *mousebutton,
  170.          int *keymods, int *keycode, int *clicks)
  171. {   
  172.     int evnt;               /* Type d'événement */
  173.     int dummy,i;            /* Divers */
  174.     int champ;              /* Champ de saisie éditable */
  175.  
  176.     objet = 0;    /* Mise à zéro avant de commencer */
  177.  
  178.     for (;;)
  179.     {
  180.         evnt = evnt_multi (MU_MESAG | MU_BUTTON | MU_KEYBD, 1, 1, *button,
  181.                           0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  182.                           message, 10, 0, mousex, mousey,
  183.                           mousebutton, keymods, keycode, clicks);
  184.     
  185.         if (evnt & MU_MESAG)
  186.             return evnt;
  187.             
  188.         if (evnt & MU_KEYBD)    /* Si événement clavier */
  189.         {        /* Si la fenêtre formulaire est au 1° plan : */
  190.             if (thefrontwin && thefrontwin->form)
  191.             {
  192.                 OBJECT *adr = thefrontwin->form;  /* Adresse formulaire sur lequel on travaille */
  193.                 
  194.                 if ((*keycode == 0x720D) || (*keycode == 0x1C0D)) /* Si <Return> ou <Enter> */
  195.                 {     /* Chercher bouton DEFAULT s'il y en a */
  196.                     i = 0;  /* En partant de la racine */
  197.                     do    /* Pour chaque objet */
  198.                     {
  199.                         if (adr[i].ob_flags & DEFAULT)  /* Si objet défaut */
  200.                         {
  201.                             objc_change(adr, i, 0, adr->ob_x, adr->ob_y,
  202.                                         adr->ob_width, adr->ob_height, SELECTED, REDRAW);
  203.                             evnt = MU_BUTTON; /* Modifier type d'événement */
  204.                             objet = i;        /* Enregistrer l'objet */
  205.                             return (evnt);    /* Retourner l'événement */
  206.                         }
  207.                     } while (! (adr[i++].ob_flags & LASTOB)); /* Jusqu'au dernier objet */
  208.                 }
  209.                 else if (edit)      /* S'il y a un champ éditable */
  210.                 {
  211.                     if (*keycode == 0x5000)      /* Si flèche vers le bas */
  212.                     {
  213.                         champ = next (adr); /* Chercher champ suivant */
  214.                         if (champ > -1) /* S'il y en a un */
  215.                         {
  216.                             objc_edit (adr, edit, 0, &pos_edit, ED_END);   /* Désactiver */
  217.                             edit = champ;   /* Nouvel éditable */
  218.                             objc_edit (adr, edit, 0, &pos_edit, ED_INIT);  /* Réactiver */
  219.                         }
  220.                     }
  221.                     else if (*keycode == 0x4800) /* Si flèche vers le haut */
  222.                     {
  223.                         champ = prev (adr); /* Chercher champ précédent */
  224.                         if (champ > -1) /* S'il y en a un */
  225.                         {
  226.                             objc_edit (adr, edit, 0, &pos_edit, ED_END);   /* Désactiver */
  227.                             edit = champ;   /* Nouvel éditable */
  228.                             objc_edit (adr, edit, 0, &pos_edit, ED_INIT);  /* Réactiver */
  229.                         }
  230.                     }
  231.                     else                    /* Si autre touche */
  232.                     {   /* Le GEM s'occupe de tout */
  233.                         objc_edit (adr, edit, *keycode, &pos_edit, ED_CHAR);
  234.                     }
  235.                 }
  236.              }
  237.              else
  238.                  return evnt;
  239.         }
  240.     
  241.         if (evnt & MU_BUTTON)   /* Si événement clic souris */
  242.         {
  243.             const int whandle = wind_find (*mousex, *mousey);  /* Handle fenêtre cliquée */
  244.  
  245.             if (whandle)      /* A t-on cliqué sur une fenêtre ? */
  246.             { 
  247.                 windowptr thewin = findwindowptr(whandle);
  248.  
  249.                 if ( (thewin == thefrontwin) && thewin->form)   /* Si on a cliqué la fenêtre formulaire de 1° plan */
  250.                 {
  251.                     OBJECT *adr = thewin->form;  /* Adresse formulaire sur lequel on travaille */
  252.  
  253.                     objet = objc_find(adr, 0, MAX_DEPTH, *mousex, *mousey); /* Objet cliqué */
  254.                     if (objet > -1)     /* Si on a cliqué sur un objet */
  255.                     {
  256.                         if (adr[objet].ob_state & DISABLED)         /* Si l'objet est désactivé */
  257.                             return 0;
  258.  
  259.                         if (! (adr[objet].ob_flags & TOUCHEXIT) )    /* Si ce n'est pas un TOUCHEXIT */
  260.                         {
  261.                             while (*mousebutton)  /* Attendre bouton souris relaché */
  262.                                 graf_mkstate (&dummy, &dummy, mousebutton, &dummy);
  263.                         }
  264.                         
  265.                         if (adr[objet].ob_flags & SELECTABLE)
  266.                         {
  267.                             if ( !(adr[objet].ob_flags & RBUTTON) )   /* Si sélectable simple */
  268.                             {
  269.                                 adr[objet].ob_state ^= SELECTED;    /* Inverser l'état de l'objet */
  270.                                 objc_draw (adr, objet, MAX_DEPTH,   /* Redessiner l'objet */
  271.                                             adr->ob_x, adr->ob_y,
  272.                                             adr->ob_width, adr->ob_height);
  273.                             }
  274.                             else if ( !(adr[objet].ob_state & SELECTED) )   /* Si sélectable simple */
  275.                             {
  276.                                 int j = objet;                      /* Partir de cet objet */
  277.         
  278.                                 objc_change(adr, objet, 0, adr->ob_x, adr->ob_y,
  279.                                             adr->ob_width, adr->ob_height, SELECTED, REDRAW);  /* Le sélectionner */
  280.                                 i = parent (adr, j);        /* Chercher le père */
  281.                                 j = adr[i].ob_head;         /* Partir du 1° enfant... */
  282.                                 i = adr[i].ob_tail;         /* jusqu'au dernier. */
  283.                                 do
  284.                                 {
  285.                                     if ((adr[j].ob_flags & RBUTTON) && (j != objet) &&
  286.                                         (adr[j].ob_state & SELECTED))
  287.                                     {   /* Les mettre en normal si RBUTTON sauf l'objet cliqué. */
  288.                                         objc_change(adr, j, 0, adr->ob_x, adr->ob_y,
  289.                                                      adr->ob_width, adr->ob_height, NORMAL, REDRAW);
  290.                                     }
  291.                                     j = adr[j].ob_next;                       /* Au suivant... */
  292.                                 } while ((j <= i) && (j > adr[i].ob_next)); /* jusqu'au dernier. */
  293.                             }
  294.                         }
  295.         
  296.                         if (adr[objet].ob_flags & EDITABLE)         /* Si éditable */
  297.                         {
  298.                             objc_edit (adr, edit, 0, &pos_edit, ED_INIT);  /* Réactiver curseur */
  299.                             edit = objet;                     /* Nouvel éditable courant */
  300.                             objc_edit (adr, edit, 0, &pos_edit, ED_END);   /* Désactiver curseur */
  301.                         }
  302.                     }
  303.                 }
  304.             }
  305.             return evnt;
  306.         }
  307.     }
  308. }
  309.  
  310. /*
  311.     name: parent
  312.     utility: Cherche le père d'un objet
  313.     comment: 
  314.     parameters:
  315.     return:
  316.     date: january 1994
  317.     author: C. Attard
  318.     modifications:
  319. */
  320. static int parent (OBJECT *adr, int object)
  321. {   /* Retourne l'objet père d'un objet */
  322.     register int i = object;                     /* Partir de cet objet */
  323.  
  324.   do
  325.   {
  326.     i = adr[i].ob_next;           /* Passer au suivant... */
  327.   } while (i > object);           /* Jusqu'à revenir au père. */
  328.  
  329.   return i;                       /* Retourner le père */
  330. }
  331.  
  332. /*
  333.     name: next
  334.     utility: Chercher l'éditable suivant
  335.     comment: 
  336.     parameters:
  337.     return:
  338.     date: january 1994
  339.     author: C. Attard
  340.     modifications:
  341. */
  342. static int next (OBJECT *adr)
  343. {     
  344.     int pere, vu = 1, ob = edit;
  345.  
  346.         /* Tant qu'on n'est pas au dernier objet */
  347.     while ( !(adr[ob++].ob_flags & LASTOB) )
  348.     {   
  349.         pere = parent (adr, ob);  /* Chercher son père */
  350.             /* Si ce n'est pas la racine et pas HIDETREE */
  351.         while ( (pere > 0) && (vu) )
  352.         {       /* Si le père est HIDETREE */
  353.             if (adr[pere].ob_flags & HIDETREE)
  354.                 vu = 0;   /* l'objet n'est pas visible */
  355.             pere = parent (adr, pere);  /* Père suivant */
  356.         }
  357.         if (vu) /* Si l'objet est visible */
  358.             if ( (adr[ob].ob_flags & EDITABLE) && 
  359.                  ( !(adr[ob].ob_flags & HIDETREE) ) &&
  360.                  ( !(adr[ob].ob_state & DISABLED) ) )  /* Si éditable actif */
  361.                 return ob;  /* Retourner son numéro */
  362.   }
  363.   return -1;  /* Sinon, -1 */
  364. }
  365.  
  366. /*
  367.     name: prev
  368.     utility: Chercher l'éditable précédent
  369.     comment: 
  370.     parameters:
  371.     return:
  372.     date: january 1994
  373.     author: C. Attard
  374.     modifications:
  375. */
  376. static int prev (OBJECT *adr)
  377. {  
  378. int pere, vu = 1, ob = edit;
  379.  
  380.   while (ob-- > 0)    /* En arrière jusqu'à la racine */
  381.   {
  382.     pere = parent (adr, ob);    /* Père de l'objet */
  383.       /* Si ce n'est pas la racine et pas HIDETREE */
  384.     while ((pere > 0) && (vu))
  385.     {   /* Si le père est HIDETREE */
  386.       if (adr[pere].ob_flags & HIDETREE)
  387.         vu = 0;   /* L'objet n'est pas visible */
  388.       pere = parent (adr, pere);  /* Père suivant */
  389.     }
  390.     if (vu) /* Si l'objet est visible */
  391.       if ((adr[ob].ob_flags & EDITABLE) &&
  392.           (! (adr[ob].ob_flags & HIDETREE)) &&
  393.           (! (adr[ob].ob_state & DISABLED)))  /* Si éditable actif */
  394.         return ob;  /* Retourner son numéro */
  395.   }
  396.   return -1;  /* Sinon, -1 */
  397. }
  398.